<?php
//抽象策略角色
abstract class Strategy{
	abstract function settlement($price);
}
//具体策略角色
//普通商品
class GoodsStrategy extends Strategy{
	public function settlement($price){
		echo "普通商品价格：".$price.'Ԫ<br/>';
	}
}
//打折商品
class DisGoodsStrategy extends Strategy{
	public function settlement($price){
		echo "打折商品价格：".($price*0.9).'Ԫ<br/>';
	}
}
//减价商品
class ReductionGoodsStrategy extends Strategy{
	public function settlement($price){
		echo "减价商品价格：".($price-20).'Ԫ<br/>';
	}
}
//环境角色
class Context{
	private $strategy = null;
	
	function __construct(Strategy $strategy){
		$this->strategy = $strategy;
	}
	
	
	public function pay($price){
		return $this->strategy->settlement($price);
	}
}

$context = new Context(new GoodsStrategy);
$context->pay(100);

$context = new Context(new DisGoodsStrategy);
$context->pay(100);

$context = new Context(new ReductionGoodsStrategy);
$context->pay(100);